package com.cy.cur.heima;

import lombok.extern.slf4j.Slf4j;
import org.testng.annotations.Test;
import sun.misc.Unsafe;

@Slf4j
public class ThreadState {

    public static void main(String[] args) throws InterruptedException {

        Unsafe unsafe = Unsafe.getUnsafe();
        unsafe.compareAndSwapInt(null,1,1,1);


        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }

                }
            }
        });

        t1.start();
        Thread.sleep(1000);
        t1.interrupt();
        Thread.sleep(1000);
        System.out.println(t1.getState());
    }

    @Test
    public void t1() throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                // try {
                //     Thread.sleep(2000);
                // } catch (InterruptedException e) {
                //    e.printStackTrace();
                // }
                log.info("===={}",Thread.currentThread().getState());
            }
        });
        log.info("{}",t1.getState());
        t1.start();
        Thread.sleep(1000);
        log.info("{}",t1.getState());
        // t1.interrupt();
        Thread.sleep(1000);
        log.info("over{}",t1.getState());

    }

    @Test
    public void t2() throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){

                }
            }
        });

        t1.start();
        Thread.sleep(1000);
        t1.interrupt();
    }
}
